package com.example.util;

import java.util.HashMap;

/*
 * 返回值封装
 *
 * */
public class Result extends HashMap<String, Object> {
    //        无参构造  当返回结果对象 内置成功信息
    private Result() {
        super.put("code", 200);
        super.put("msg", "success");
    }

    //    成功返回
    public static Result success() {
        return new Result();
    }

    public static Result success(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    //    异常返回
    public static Result error(String mag, int code) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", mag);
        return result;
    }
    public static Result error(String mag) {
        return error(mag,500);
    }

    public static Result error() {
        return error("有异常了 检查一下");
    }
    public Result put(String key,Object val){
        super.put(key,val);
        return this;
    }

}
